import {
  PutRes,
  MediaGroup,
  PageResult,
  DisableRes,
  putMediaGroupDto,
  MediaGroupGateway,
  disableMediaGroupDto,
  MediaGroupInterfaceWithPrimary,
} from "qqlx-core";

import { ViewBase, ViewBaseAction } from "@view/view-base";
import { MediaGroupSchema } from "@/pond/schema-media";

export class ViewMediaGroup extends ViewBase<MediaGroup> implements ViewBaseAction<MediaGroup>, MediaGroupInterfaceWithPrimary<{}> {
  private static instance: ViewMediaGroup;
  static getInstance(options?: { isSingleton?: boolean }) {
    if (options?.isSingleton === false) {
      return new ViewMediaGroup();
    }

    if (!this.instance) this.instance = new ViewMediaGroup();
    return this.instance;
  }

  private constructor() {
    super();
    this.initial();
    this.insertDefaultCondition();
  }
  getSchema(): MediaGroup {
    return new MediaGroupSchema();
  }

  async get() {
    this.pending();
    const { list, total } = await this.$request.get<{}, PageResult<MediaGroup>>(MediaGroupGateway.path);
    this.data.entityListTotal = total;
    return { list, total };
  }

  async put() {
    this.pending();
    const dto = { schema: this.data.schema };
    return this.$request.put<putMediaGroupDto, PutRes<MediaGroup>>(MediaGroupGateway.path, dto);
  }

  async disable(dto: disableMediaGroupDto) {
    this.pending();
    return this.$request.delete<disableMediaGroupDto, DisableRes>(MediaGroupGateway.path, dto);
  }
}
